package cn.com.bluemoon.daps.api.model.factory;

import cn.com.bluemoon.daps.api.model.RemoteDataModelTableIndexService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.model.entity.DapDataModelSubordinateKey;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteDataModelTableIndexServiceFallbackFactory implements FallbackFactory<RemoteDataModelTableIndexService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteDataModelTableIndexServiceFallbackFactory.class);

    @Override
    public RemoteDataModelTableIndexService create(Throwable throwable) {
        log.error("模型索引服务异常！", throwable.getMessage());
        return new RemoteDataModelTableIndexService() {
            @Override
            public ResultBean<Boolean> updateById(String id, DapDataModelSubordinateKey newT) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "更新表索引失败");
            }

            @Override
            public ResultBean<Boolean> removeById(String id) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "删除表索引失败");
            }

            @Override
            public ResultBean<String> saveIndex(DapDataModelSubordinateKey newT) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "新增表索引·失败");
            }
        };
    }
}
